package com.yenlien.traceyun.usercenter.controller;

import com.yenlien.traceyun.usercenter.entity.App;
import com.yenlien.traceyun.usercenter.exception.UserException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author: bigwangy@sina.com
 * @create: 2020-03-04
 * @description:
 **/

@RestController
@RequestMapping("config")
@RefreshScope
public class TestNacosController {

    @Value("${c.useLocalCache:false}")
    private boolean useLocalCache;

    @Value("${c.testbb:xdfsdfsd}")
    private String testbb;

    @RequestMapping(value = "/get", method = RequestMethod.GET)
    @ResponseBody
    public Object get() {
        return "useLocalCache:" + useLocalCache + "   testbb:" + testbb;
    }

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public Object testThrow() {
        throw new UserException("E0001");
    }

    @RequestMapping(value = "/upload", method = RequestMethod.POST)
    @ResponseBody
    public Object upload(App app, HttpServletRequest request) {
        List<MultipartFile> files = ((MultipartHttpServletRequest) request).getFiles("files");
        System.out.println(app.toString());
        System.out.println("file:" + files.size());
        return "ok";
    }
}
